# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: settings_provider\__init__.py
__author__ = "sanyi"


class Settings:
    no_value = object()

    def __init__(self):
        self._document = {}

    def load(self, document):
        self._document = document

    @property
    def document(self):
        return self._document

    def __getitem__(self, item):
        if not item:
            raise KeyError(item)
        result = self.get(item, self.no_value)
        try:
            if result == self.no_value:
                raise KeyError(item)
        except TypeError:
            pass

        return result

    def set(self, path, value):
        keys = path.split(".")
        data_location = self._document
        for i in range(0, len(keys) - 1):
            key = keys[i]
            if key not in data_location:
                data_location[key] = {}
            data_location = data_location[key]

        data_location[keys[-1]] = value

    def get(self, path, default=None):
        try:
            return self._document[path]
        except KeyError:
            pass

        if not path:
            return default
        if not isinstance(path, (list, tuple)):
            path = path.split(".")
        try:
            result = self._document
            for part in path:
                result = result[part]

            return result
        except KeyError:
            return default


settings = Settings()
